<template>
  <el-dialog title="双击 选定单位" :visible.sync="visible" center>
    <el-container>
      <el-header style="padding: 0;border-bottom: none;height: auto">
        <el-col :xs="9" :sm="9" :lg="9">
          <el-input prefix-icon="el-icon-search" v-model="dw_name" clearable placeholder="单位名称/单位名称拼音首字母"></el-input>
        </el-col>
        <el-col :xs="12" :sm="12" :lg="12">
          <el-button type="primary" @click="searchDepartment" class="btn-search">查询</el-button>
        </el-col>
      </el-header>
      <el-main >
        <el-table :data="tableData" stripe v-loading="dwLoading"
                  @row-dblclick="dbSelectDepartment"
                  highlight-current-row
                  fit border>
          <el-table-column align="center" fixed prop="orgname" label="单位名称" min-width="150"></el-table-column>
          <el-table-column align="center" min-width="150" prop="parentorgname" label="上级单位"></el-table-column>
          <el-table-column align="center" min-width="150" prop="orgtypename" label="机构类型"></el-table-column>
          <el-table-column align="center" min-width="200" prop="orgtel" label="负责人联系电话"></el-table-column>
          <el-table-column prop="headername" label="负责人"></el-table-column>
        </el-table>
      </el-main>
      <el-footer>
        <el-pagination
          small
          background
          layout="total,sizes,prev,pager,next,jumper"
          :total="total"
          :page-size="pageSize"
          :page-sizes="[10,20,30,50]"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
          style="margin-top: 10px;"
        ></el-pagination>
      </el-footer>
    </el-container>
  </el-dialog>
</template>

<script>
  import { searchUnitByExtraParam } from '../../../api/public/searchUnit'
  import { selDictonaryValue } from '../../../api/dictionary'

  export default {
    name: 'department',
    data() {
      return {
        fit: true,
        dw_name: '',
        visible: false,
        tableData: [],
        pageNum: 1,
        total: 0,
        pageSize: 10
      }
    },
    props: [
      'dialogDwVisible',
      'extraParam',
      'dwLoading'
    ],
    watch: {
      visible(val) {
        this.$emit('update:dialogDwVisible', val)
      },
      dialogDwVisible(val) {
        this.visible = val
        if (val) {
          this.searchUnitByExtraParam()
        }
      }
    },
    methods: {
      searchUnitByExtraParam() {
        searchUnitByExtraParam(this.pageNum, this.pageSize, this.dw_name, this.extraParam).then(res => {
          selDictonaryValue(res).then(resp => {
            this.tableData = resp.list
            this.total = resp.count
            this.pageSize = resp.pageSize
            this.$emit('update:dwLoading', false)
          })
        })
      },
      searchDepartment() {
        this.$emit('update:dwLoading', true)
        this.searchUnitByExtraParam()
      },
      dbSelectDepartment(row, event) {
        this.$emit('setDepartment', row)
        this.visible = false
      },
      handleCurrentChange(val) {
        this.pageNum = val
        this.searchDepartment()
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.searchDepartment()
      }
    }
  }
</script>

<style scoped>
</style>
